<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="出库单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入出库单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入商品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作人" prop="operator">
        <el-input
          v-model="queryParams.operator"
          placeholder="请输入操作人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库时间">
        <el-date-picker
          v-model="daterangeOutboundTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wms:outbound:record:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="出库单号" align="center" prop="orderNo" />
      <el-table-column label="商品编码" align="center" prop="itemCode" />
      <el-table-column label="商品名称" align="center" prop="itemName" />
      <el-table-column label="仓库" align="center" prop="warehouseName" />
      <el-table-column label="库位" align="center" prop="locationCode" />
      <el-table-column label="批次号" align="center" prop="batchNo" />
      <el-table-column label="容器号" align="center" prop="containerNo" />
      <el-table-column label="出库数量" align="center" prop="outboundQty" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="操作人" align="center" prop="operator" />
      <el-table-column label="出库时间" align="center" prop="outboundTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outboundTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOutboundRecord } from "@/api/wms/outboundRecord";

export default {
  name: "OutboundRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库记录表格数据
      recordList: [],
      // 出库时间时间范围
      daterangeOutboundTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        itemCode: null,
        itemName: null,
        operator: null,
        beginOutboundTime: null,
        endOutboundTime: null
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询出库记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.beginOutboundTime = null;
      this.queryParams.endOutboundTime = null;
      if (null != this.daterangeOutboundTime && '' != this.daterangeOutboundTime) {
        this.queryParams.beginOutboundTime = this.daterangeOutboundTime[0];
        this.queryParams.endOutboundTime = this.daterangeOutboundTime[1];
      }
      listOutboundRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOutboundTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wms/outboundRecord/export', {
        ...this.queryParams
      }, `outboundRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>